/**
 * @file test_Config.cpp
 * @author  haifeng (haifengxiao@icloud.com)
 * @brief
 * @version 0.1
 * @date 2021-07-17
 *
 * @copyright Copyright (c) 2021
 *
 */

#include <yaml-cpp/yaml.h>

#include "Logger.h"
#include "LoggerManager.h"
#include "Config.h"

Chen::Conf::ConfigVal<int>::ptr g_int =
Chen::Conf::Config::Lookup("system.port", (int)8080, "system.port");

void print_yaml(const YAML::Node& node, int level) {
    if (node.IsScalar()) {
        std::cout << std::string(level * 4, ' ')
            << node.Scalar() << " - "
            << node.Type() << " - "
            << level << std::endl;
    }
    else if (node.IsNull()) {
        std::cout << std::string(level * 4, ' ')
            << "Null - " << " - " << node.Type()
            << " - " << level << std::endl;
    }
    else if (node.IsMap()) {
        for (auto it = node.begin();
            it != node.end();it++) {
            std::cout << std::string(level * 4, ' ')
                << it->first << " - "
                << it->second.Type() << " - "
                << level << std::endl;
            print_yaml(it->second, level + 1);
        }
    }
    else if (node.IsSequence()) {
        for (size_t i = 0; i < node.size(); i++) {
            std::cout << std::string(level * 4, ' ')
                << i << " - "
                << node[i].Type() << " - "
                << level << std::endl;
            print_yaml(node[i], level + 1);
        }
    }

}

void test_yaml() {
    YAML::Node root = YAML::LoadFile("/home/kr/chenJ/Chen/bin/Conf/test.yml");
    print_yaml(root, 0);
}

void test_Config() {

    std::cout << "before: " << g_int->getValue() << std::endl;
    //加载配置文件
    YAML::Node root = YAML::LoadFile("/home/kr/chenJ/Chen/bin/Conf/test.yml");
    Chen::Conf::Config::LoadFromYaml(root);

    std::cout << "after: " << g_int->getValue();
}

int main(int argc, char** argv) {

    std::cout << g_int->getValue() << std::endl;
    //test_yaml();
    test_Config();
    //CHEN_LOG_DEBUG(CHEN_LOG_ROOT()) << g_int->getValue();
}
